#include "object_pool/pool.hpp"
#include "sdlengine.hpp"

using namespace sdl_engine;
using namespace sdl_engine::component::object_pool;

class TestObject: public GCObject {
public:
    TestObject(int id): id_(id) {}
    inline int GetID() const { return id_; }

private:
    int id_;
};

int main([[ maybe_unused ]] int argc,
         [[ maybe_unused ]] char** argv) {
    Unique<GCObjectPool> pool(new GCObjectPool);
    TestObject* obj1 = pool->New<TestObject>(1);
    TestObject* obj2 = pool->New<TestObject>(2);
    TestObject* obj3 = pool->New<TestObject>(3);

    assert(obj1->GetID() == 1);
    assert(obj2->GetID() == 2);
    assert(obj3->GetID() == 3);
    assert(pool->GetSize() == 3);
    assert(obj1->GetObjectIdx() == 0);
    assert(obj2->GetObjectIdx() == 1);
    assert(obj3->GetObjectIdx() == 2);

    obj1->DelSelf();
    assert(pool->GetSize() == 3);

    pool->Gc();
    assert(pool->GetSize() == 2);

    obj2->ImDelSelf();
    assert(pool->GetSize() == 1);

    TestObject* tmpObj = pool->New<TestObject>(4);
    assert(tmpObj->GetID() == 4);
    assert(pool->GetSize() == 2);
    assert(tmpObj->GetObjectIdx() == 0);

    tmpObj = pool->New<TestObject>(5);
    assert(tmpObj->GetObjectIdx() == 1);

    tmpObj = pool->New<TestObject>(6);
    assert(tmpObj->GetObjectIdx() == 3);

    assert(pool->GetSize() == 4);

    pool->Clear();
    assert(pool->GetSize() == 0);
    return 0;
}
